package thinkingJava.chapter14;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.regex.Pattern;

class Base {int x; int y; int z; String name;public void printf() {}}
class Derived extends Base {}

public class FamilyVsExtractType {
	static void test(Object x) {
		print("The type of x : " + x.getClass());
		print("x instanceof Base : " + (x instanceof Base));
		print("x instanceof Derived : " + (x instanceof Derived));
		print("Base.isInstance(x) : " + Base.class.isInstance(x));
		print("Derived.isInstance(x) : " + Derived.class.isInstance(x));
		print("x.getClass == Base.class : " + (x.getClass() == Base.class));
		print("x.getClass == Derived.class : " + (x.getClass() == Derived.class));
		print("x.getClass().equals(Base.class) : " + (x.getClass().equals(Base.class)));
		print("x.getClass().equals(Derived.class) : " + (x.getClass().equals(Derived.class)));
	}
	public static void print(Object o) {
		System.out.println(o);
	}
	public static void main(String[] args) {
//		Base base = new Base();
//
//		Derived derived = new Derived();
//		test(base);
//		test(derived);
		Field[] fields = Base.class.getDeclaredFields();
		Method[] method = Base.class.getDeclaredMethods();
		Pattern p = Pattern.compile("\\w+\\.");
		for (Field field : fields) {
//			System.out.println(field.toGenericString());
			System.out.println(p.matcher(field.toString()).replaceAll(""));
		}
		System.out.println("------");
		for (Method m : method) {
			System.out.println(p.matcher(m.toString()).replaceAll(""));
		}
	}
}
